<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>料框状态记录表</title>
</head>
<body>
<section>
    <div>
        <!--<div class="layui-card">
            <div class="layui-card-body">
                <div>
                    <button ADP_BTN method="addEntity"><i class="layui-icon layui-icon-add-circle-fine"></i>增加</button>
                    <button adp_btn method="deleteAllEntity"><i class="layui-icon layui-icon-close"></i>删除</button>
                </div>
            </div>
        </div>-->
        <div class="layui-card">
            <div class="adp-content">
                <form id="queryForm"></form>
                <table id="queryTable"></table>
            </div>
        </div>
    </div>
</section>
<div style="width: 600px;display: none;" id="mergeFormDiv">
    <form action="" method="post" id="mergeForm" class="adp-center"></form>
</div>
</body>
</html>
<script src="../static/adp/import.js"></script>

<script type="text/html" id="OPERATION_ROW_TPL">
    <a class="layui-btn layui-btn-sm" lay-event="edit"> <i class="layui-icon layui-icon-edit"></i>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del"><i
            class="layui-icon layui-icon-delete"></i>删除</a>
</script>
<!--<script type="text/html" id="USER_ROLE_TPL">-->
<!--{{# layui.each(d.roles, function(index, item){ }}-->
<!--<span class="layui-badge layui-bg-blue">{{= item.roleName}}</span>-->
<!--{{# }); }}-->
<!--</script>-->
<script type="text/javascript">
    var queryform = $("#queryForm").adpForm({
        elem: [{type: "text", label: "料框编号", name: "containerId", placeholder: "请输入料框遍号"},
            {type: "select", label: "数据状态", name: "isAbnormal", placeholder: "请选择状态",data:[{key:0,value:"全部"},{key:true,value:"异常"},{key:false,value:"正常"}]},
            {type: "date", label: "按日期查询 从", name: "startDate", placeholder: "请输入关键字"},
            {type: "date", label: "至", name: "endDate", placeholder: "请输入关键字"}],
        button: [{type: "submit", label: "查询", method: "query", icon: 'query'},{type: "reset", label: "重置"}],
        methods: {
            query: function query(data) {
                /*console.log(data);
                if(data.isAbnormal=="true"){
                    data.isAbnormal=true;
                }else{
                    data.isAbnormal=false;
                }
                queryTable.reload(data);*/
                queryTable.reload(setStatus());
            }
        }
    });
    var mergeForm = $("#mergeForm").adpForm({
        layout: 'vertical',
        elem: [
            {type: "text", label: "料框编号", name: "containerId", verify: "required", placeholder: "请输入内容"},
            {type: "select", label: "数据状态", name: "isAbnormal", placeholder: "请输入内容",data:[{key:true,value:"异常"},{key:false,value:"正常"}]},
            {type: "date", label: "状态改变日期", name: "transformDate", format: 'yyyy-MM-dd HH:mm:ss', istime: 'true'},
            {type: "hidden", name: "id"}
        ],
        button: [
            {type: "submit", label: "保存", method: "submit"},
            {type: "reset", label: "重置"}
        ],
        methods: {
            submit: function submit(data) {
                if(data.isAbnormal=="异常"){
                    data.isAbnormal=true;
                }else {
                    data.isAbnormal=false;
                }
                SV("ContainerStatusTransformRecord")("save")(data);
                $("#mergeFormDiv").close();
                // queryTable.reload(queryform.data());
                queryTable.reload(setStatus());
            }
        }

    });

    var queryTable = $("#queryTable").adpTable({
        url: '../rs/ContainerStatusTransformRecord/list',
        // where: setStatus(),
        where: queryform.data(),
        cols: [[
            {field: 'id', title: 'ID', type: 'checkbox', width: 30, sort: true, fixed: 'left'},
            {field: 'containerId', title: '料框编号', width: 180},
             {field:'isAbnormal',title: '数据状态',width: 180,templet:'#abc'},
            {field: 'transformDate', title: '状态改变日期', width: 180},
            {fixed: 'right', title: '操作', width: 200, align: 'center', toolbar: '#OPERATION_ROW_TPL'}
        ]],
        methods: {
            edit: function edit(data, tr) {
                $("#mergeFormDiv").open("编辑任务");
                mergeForm.reset();
                if(data.isAbnormal){
                    data.isAbnormal="异常";
                }else{
                    data.isAbnormal="正常";
                }
                mergeForm.data(data);
            },
            del: function del(data, tr) {
                layer.confirm('真的删除行么', function (index) {
                    SV("ContainerStatusTransformRecord")("delete")({ids: [data.id]});
                    // queryTable.reload(queryform.data());
                    queryTable.reload(setStatus());
                    layer.close(index);
                });
            }
        }
    });


    function addEntity() {
        return $("#mergeFormDiv").open("添加任务", {
            success: function success() {
                return mergeForm.reset();
            }
        });
    }
    function deleteAllEntity(arr) {
        var _queryTable$checkStat = queryTable.checkStatus(),
            data = _queryTable$checkStat.data;
        var ids = new Array();
        $.each(data, function (n, value) {
            ids.push(value.id);
        });
        layer.confirm('真的删除行么', function (index) {
            Deferred("ContainerStatusTransformRecord")("delete")({
                "ids": ids
            }).then(function () {
                queryTable.reload(queryform.data());
                layer.close(index);
            });
        });
    }

    function setStatus() {
        var para = queryform.data();
        if (0 == para.statusVo) {
            para.isAbnormal = null;
        }
        console.log(para);
        return para;
    }
</script>
<script type="text/html" id="abc">
    {{#if(d.isAbnormal==true){d.isAbnormal="异常"}}
    {{d.isAbnormal}}
    {{#}else{d.isAbnormal="正常"}}
    {{d.isAbnormal}}
    {{#  } }}
</script>